package com.ycy.analyzer.max;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.junit.Test;

import java.util.List;
import java.util.Map;

public class MaxLen2 {

  static Map<String, String> dict = Maps.newHashMap();

  static {
    dict.put("中华", null);
    dict.put("中华人民", null);
  }


  @Test
  public void test() {

    List<String> list = Lists.newArrayList();

    //
    String text = "中华民族万岁";

    int position = 0;


    int maxLen = 4;

    //长度
    int len = maxLen;

    while (true) {
      String str = text.substring(position, position + len);

      if (len <= 1) {
        position = position + len;
        list.add(str);
        break;
      }

      if (dict.containsKey(str)) {
        //在词典中查询到了
        position = position + len;
        list.add(str);
        break;
      } else {
        //没查询到，len --
        len--;
      }
    }

    System.out.println(position);

    list.forEach(s -> System.out.println(s));

  }

}
